
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/01/2012 13:36:31
-- Generated from EDMX file: C:\Temp\Jeffch\Spike.ServiceFramework\Spike.ServiceFramework.Audit\Entities\Audit.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Spike];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ClientTraceHeaders_ClientTraces]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ClientTraceHeaders] DROP CONSTRAINT [FK_ClientTraceHeaders_ClientTraces];
GO
IF OBJECT_ID(N'[dbo].[FK_ServiceTraceHeaders_ServiceTraces]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ServiceTraceHeaders] DROP CONSTRAINT [FK_ServiceTraceHeaders_ServiceTraces];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[ClientTraceHeaders]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ClientTraceHeaders];
GO
IF OBJECT_ID(N'[dbo].[ClientTraces]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ClientTraces];
GO
IF OBJECT_ID(N'[dbo].[ServiceTraceHeaders]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ServiceTraceHeaders];
GO
IF OBJECT_ID(N'[dbo].[ServiceTraces]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ServiceTraces];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'ClientTraceHeaders'
CREATE TABLE [dbo].[ClientTraceHeaders] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [ClientTraceID] bigint  NOT NULL,
    [Header] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ClientTraces'
CREATE TABLE [dbo].[ClientTraces] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Reply] nvarchar(max)  NULL,
    [URI] nvarchar(500)  NOT NULL,
    [Directory] nvarchar(500)  NOT NULL,
    [MachineName] nvarchar(100)  NOT NULL,
    [UserName] nvarchar(100)  NOT NULL,
    [DomainName] nvarchar(100)  NOT NULL,
    [CorrelationID] uniqueidentifier  NULL,
    [AfterReceiveReply] datetime  NULL,
    [BeforeSendRequest] datetime  NULL,
    [Request] nvarchar(max)  NULL,
    [ApplicationDomain] nvarchar(500)  NOT NULL,
    [EventName] nvarchar(100)  NOT NULL
);
GO

-- Creating table 'ServiceTraceHeaders'
CREATE TABLE [dbo].[ServiceTraceHeaders] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [ServiceTraceID] bigint  NOT NULL,
    [Header] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ServiceTraces'
CREATE TABLE [dbo].[ServiceTraces] (
    [ID] bigint IDENTITY(1,1) NOT NULL,
    [Reply] nvarchar(max)  NULL,
    [URI] nvarchar(500)  NOT NULL,
    [Directory] nvarchar(500)  NOT NULL,
    [MachineName] nvarchar(100)  NOT NULL,
    [UserName] nvarchar(100)  NOT NULL,
    [DomainName] nvarchar(100)  NOT NULL,
    [CorrelationID] uniqueidentifier  NULL,
    [AfterReceiveRequest] datetime  NULL,
    [BeforeSendReply] datetime  NULL,
    [ContractName] nvarchar(300)  NOT NULL,
    [ContractNamespace] nvarchar(500)  NOT NULL,
    [Request] nvarchar(max)  NULL,
    [ApplicationDomain] nvarchar(500)  NOT NULL,
    [EventName] nvarchar(100)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'ClientTraceHeaders'
ALTER TABLE [dbo].[ClientTraceHeaders]
ADD CONSTRAINT [PK_ClientTraceHeaders]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ClientTraces'
ALTER TABLE [dbo].[ClientTraces]
ADD CONSTRAINT [PK_ClientTraces]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ServiceTraceHeaders'
ALTER TABLE [dbo].[ServiceTraceHeaders]
ADD CONSTRAINT [PK_ServiceTraceHeaders]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ServiceTraces'
ALTER TABLE [dbo].[ServiceTraces]
ADD CONSTRAINT [PK_ServiceTraces]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ClientTraceID] in table 'ClientTraceHeaders'
ALTER TABLE [dbo].[ClientTraceHeaders]
ADD CONSTRAINT [FK_ClientTraceHeaders_ClientTraces]
    FOREIGN KEY ([ClientTraceID])
    REFERENCES [dbo].[ClientTraces]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientTraceHeaders_ClientTraces'
CREATE INDEX [IX_FK_ClientTraceHeaders_ClientTraces]
ON [dbo].[ClientTraceHeaders]
    ([ClientTraceID]);
GO

-- Creating foreign key on [ServiceTraceID] in table 'ServiceTraceHeaders'
ALTER TABLE [dbo].[ServiceTraceHeaders]
ADD CONSTRAINT [FK_ServiceTraceHeaders_ServiceTraces]
    FOREIGN KEY ([ServiceTraceID])
    REFERENCES [dbo].[ServiceTraces]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ServiceTraceHeaders_ServiceTraces'
CREATE INDEX [IX_FK_ServiceTraceHeaders_ServiceTraces]
ON [dbo].[ServiceTraceHeaders]
    ([ServiceTraceID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------